package com.woniu.ly.parent.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AddImg {

    //上传多张图片
    public List<String> addImg(List<MultipartFile> imgFiles){
        if (imgFiles.size()>0){
            ArrayList<String> fileNames = new ArrayList<>();
            for (MultipartFile imgFile : imgFiles) {
                String originalFilename = imgFile.getOriginalFilename();
                String fileType = originalFilename.substring(originalFilename.lastIndexOf("."));
                String filename = UUID.randomUUID() + fileType;
                try {
                    imgFile.transferTo(new File("本地路径地址" + filename));
                }catch (IOException e){
                    e.printStackTrace();
                }
                fileNames.add(filename);
            }
            return fileNames;
        }
        return null;
    }

}
